package parse.xml;

import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

import java.security.Key;
import java.util.*;

public class Test {
    public static void main(String[] args) {
        Map<String ,String >map=new HashMap<>();
        SAXReader reader=new SAXReader();
        try {
            //读取web.xml文件
            Document document=reader.read("./web.xml");
            Element readElement=document.getRootElement();
            String readName= readElement.getName();
            System.out.println("根节点的名称："+readName);
            List<Element> wedElements=readElement.elements("mime-mapping");
            System.out.println("根节点下有几个子节点："+wedElements.size());
            for (Element wedElement : wedElements) {
                Element weblement= wedElement.element("extension");
                String Key=weblement.getText();
                Element weblement1= wedElement.element("mime-type");
                String Value=weblement1.getText();
                System.out.println("extension:"+Key+"  mime-type:"+Value);
                map.put(Key,Value);

            }
            map.forEach((k ,v)-> System.out.print(k +":"+v));


        } catch (DocumentException e) {
            e.printStackTrace();
        }
    }
}
